<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="renderer" content="webkit">
    <title>网站信息</title>
    <link rel="stylesheet" href="__CSS__/pintuer.css">
    <link rel="stylesheet" href="__CSS__/admin.css">
    <link rel="stylesheet" href="__STATIC__/css/layui.css">
    <script src="__STATIC__/layui.js"></script>
    <script src="__JS__/jquery.js"></script>
    <script src="__JS__/pintuer.js"></script>
</head>
<body>
<div class="panel admin-panel">
    <div class="panel-head"><strong class="icon-reorder">流程添加</strong>&emsp;<a style="color: #3a4bfb;font-weight: bold "
                                                                               href="javascript:history.go(-1)">返回上一步</a>
    </div>
    <div class="padding border-bottom">
        <!--<a class="button border-yellow" href=""><span class="icon-plus-square-o"></span> 添加内容</a>-->
    </div>
    <form class="layui-form">
        <div class="layui-form-item">
            <div style=";margin-left: 2.5%" class="layui-inline">
                <label style="float: left;margin-top: 5%;" class="layui-form-lable">主体：</label>
                <div style="margin-top: 3%" class="layui-input-inline">
                    <select id="region_id" lay-filter="region_id" lay-search="" name="region_id">
                        <option value="{$list.region_id}" selected="selected">{$list.region}</option>
                    </select>
                </div>
            </div>
            <div style=";margin-left: 5%;" class="layui-inline">
                <label style="float: left;margin-top: 5%;" class="layui-form-lable">部门：</label>
                <div style="margin-top: 3%" class="layui-input-inline">
                    <select id="branch_id" lay-filter="branch_id" lay-search="" name="branch_id">
                        <option value="{$list.branch_id}" selected="selected">{$list.branch}</option>
                    </select>
                </div>
            </div>
            <div style=";margin-left: 9.5%;" class="layui-inline">
                <div style="margin-top: 3%" class="layui-input-inline">
                    <select lay-filter="type_approve" lay-search="" name="type_approve">
                        {volist name="type_approve" id="vo"}
                        {if condition="$list.bill_type_id eq $vo.id"}
                        <option selected="selected" value="{$vo.id}">{$vo.type_approve}</option>
                        {else /}
                        <option value="{$vo.id}">{$vo.type_approve}</option>
                        {/if}
                        {/volist}
                    </select>
                </div>
            </div>
        </div>
        <div id="box" class="layui-form-item">
            {volist name="role" id="ro" key="k"}
            <div style=";margin-left: 3%" class="layui-inline">
                <label style="float: left;margin-top: 5%;padding-right: 1%" class="layui-form-lable">第{$k}级</label>
                <div style="margin-top: 3%" class="layui-input-inline">
                    <select name="{$k}" lay-filter="{$k}">
                        {volist name="$ro.role" id="rr"}
                        {if condition="$ro.selected eq $rr.id"}
                        <option selected="selected  " value="{$rr.id}">{$rr.role}</option>
                        {else /}
                        <option value="{$rr.id}">{$rr.role}</option>
                        {/if}
                        {/volist}
                    </select>
                </div>
                <a><label style="float: right;margin-top: 5%;" class="layui-form-lable">删除</label></a>
            </div>
            {/volist}
        </div>
        <div class="layui-form-item">
            <input type="hidden" name="id" value="{$list.id}">
            <p style="margin-left: 7%" id="butten" data-method="confirmTrans" class="layui-btn layui-btn-sm">
                点击添加下一个审批</p>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button style="margin-left: 35%" class="layui-btn" name="submit" value="submit" lay-submit=""
                        lay-filter="demo">确定修改
                </button>
                <!--<button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
            </div>
        </div>

    </form>

</div>
<div>
</div>
</body>
<script>
    //删除

</script>
<script>

    layui.use(['layer', 'form'], function () {
        var layer = layui.layer
            , form = layui.form;
        var index = layer.load(1, {time: 10 * 1000});
        //关闭
        layer.close(index);
        form.on('submit(demo)', function (data_d) {
            //layer.alert(JSON.stringify(data_d.field));
            var datas = JSON.stringify(data_d.field);
            var submit = 'submit';
            $.ajax({
                type: "post",
                url: "{:url('Flow/flowsave_sub')}",
                data: {'data': datas, 'submit': submit},
                dataType: "json",
                success: function (res) {
                    //console.log(res);
                    if (res == 1) {
                        layer.msg('流程修改成功');
                        window.setTimeout("window.location=\"{:url('Flow/flowlist')}\"", 2000);
                        //window.location.href="{:url('Stafflist/index')}"
                    } else if (res == 2) {
                        layer.msg('提示：流程最少要添加一级');
                        setTimeout(function () {
                            //使用  setTimeout（）方法设定定时2000<a href="https://www.baidu.com/s?wd=%E6%AF%AB%E7%A7%92&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dWuHn4n1DkmynYmhu9uhcd0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHf4PWmsrHRdnWckPWnkrHmkrf" target="_blank" class="baidu-highlight">毫秒</a>
                            window.location.reload();//页面刷新
                        }, 2000);
                    } else {
                        layer.msg('提示：流程添加失败');
                        setTimeout(function () {
                            //使用  setTimeout（）方法设定定时2000<a href="https://www.baidu.com/s?wd=%E6%AF%AB%E7%A7%92&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dWuHn4n1DkmynYmhu9uhcd0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHf4PWmsrHRdnWckPWnkrHmkrf" target="_blank" class="baidu-highlight">毫秒</a>
                            window.location.reload();//页面刷新
                        }, 2000);
                    }
                }
            });
            return false;
        })
    });
    $(document).on('click', 'a', function () {
        console.log($(this));
        $(this).parent('div').remove()
    });
    $(document).on('click', '#butten', function () {
        //流程级别
        var num = $('#box').children('div').length;
        if (num > 9) {
            layui.use('layer', function () {
                /*var $ = layui.jquery, layer = layui.layer;
                 var active = {
                 confirmTrans: function () {
                 //配置一个透明的询问框
                 layer.msg('最多添加十级审批', {icon: 4});
                 }
                 };
                 $('.layui-form-item .layui-btn').on('click', function () {
                 var othis = $(this), method = othis.data('method');
                 active[method] ? active[method].call(this, othis) : '';
                 });*/
                var layer = layui.layer;
                layer.msg('最多添加十级审批', {icon: 4})
            })
        } else {
            var role = 'role';
            var nums = num + 1;
            $.ajax({
                type: "post",
                url: "{:url('Base/role')}",
                data: {"role": role},
                dataType: "json",
                success: function (res) {
                    if (res) {
                        var html_a = '';
                        $.each(res, function (i, item) {
                            html_a += "<option value='" + item.id + "'>" + item.role + "</option>";
                        });
                        var html_s = "<div id='" + nums + "' style='margin-left: 2%' class='layui-inline'> " +
                            "<label style='float: left;margin-top: 1%; margin-right: 5%' class='layui-form-lable'>第" + nums + "级</label> " +
                            "<div class='layui-input-inline'>" +
                            "<select style='display: block; width: 100%;' name='role_id" + nums + "' lay-filter='role_id" + nums + "' lay-search=''>";
                        var html_c = "</select> " +
                            "</div> " +
                            "<a style='float: right'>删除</a>" +
                            "</div>";
                        $('#box').append(html_s + html_a + html_c);
                    } else {
                        layui.use('layer', function () {
                            var layer = layui.layer;
                            layer.msg('失败', {icon: 5})
                        });

                    }
                }
            });
        }

        /*if (res == 1){
         $.ajax({
         type: "post",
         url: "{:url('Base/role')}",
         data: {"role":role},
         dataType: "json",
         success:function (res) {
         if (res){
         var html_a='';
         $.each(res,function (i,item) {
         html_a += "<option value='"+item.id+"'>"+item.role+"</option>";
         });
         var html_s="<div id='"+nums+"' style='margin-left: 3%' class='layui-inline'> " +
         "<label style='float: left;margin-top: 1%; margin-right: 5%' class='layui-form-label'>第"+nums+"级</label> " +
         "<div class='layui-input-inline'>" +
         "<select style='display: block; width: 100%' name='role_id"+nums+"' lay-filter='role_id"+nums+"' lay-search=''>";
         var html_c=    "</select> " +
         "</div> " +
         "<div style='float: right'><button>删除</button></div> " +
         "</div>";
         $('#box').append(html_s+html_a+html_c);
         }else {
         alert('失败')
         }
         }
         });
         //alert(1)
         }else if(res == 2){
         //alert(2)
         $.ajax({
         type: "post",
         url: "{:url('Base/role')}",
         data: {"role":role},
         dataType: "json",
         success:function (res) {
         if (res){
         var html_a='';
         $.each(res,function (i,item) {
         html_a += "<option value='"+item.id+"'>"+item.role+"</option>";
         });
         var html_s="<div id='"+nums+"' style='margin-left: 3%' class='layui-inline'> " +
         "<label style='float: left;margin-top: 1%;' class='layui-form-lable'>第"+nums+"级</label> " +
         "<div class='layui-input-inline'>" +
         "<select style='display: block; width: 100%;margin-left: 7%' name='role_id"+nums+"' lay-filter='role_id"+nums+"' lay-search=''>";
         var html_c="</select> " +
         "</div> " +
         "<div style='float: right'><button>删除</button></div> " +
         "</div>";
         $('#box').append(html_s+html_a+html_c);
         }else {
         alert('失败')
         }
         }
         });
         }else {
         //alert(0)
         $.ajax({
         type: "post",
         url: "{:url('Base/role')}",
         data: {"role":role},
         dataType: "json",
         success:function (res) {
         if (res){
         var html_a='';
         $.each(res,function (i,item) {
         html_a += "<option value='"+item.id+"'>"+item.role+"</option>";
         });
         var html_s="<div id='"+nums+"' style='margin-left: 2%' class='layui-inline'> " +
         "<label style='float: left;margin-top: 1%; margin-right: 5%' class='layui-form-lable'>第"+nums+"级</label> " +
         "<div class='layui-input-inline'>" +
         "<select style='display: block; width: 100%;' name='role_id"+nums+"' lay-filter='role_id"+nums+"' lay-search=''>";
         var html_c=    "</select> " +
         "</div> " +
         "<div style='float: right'><button >删除</button></div>" +
         "</div>";
         $('#box').append(html_s+html_a+html_c);
         }else {
         alert('失败')
         }
         }
         });
         }*/
    });


</script>
<script>
    //两级联动
    layui.use(['form'], function () {
        var form = layui.form;
        var num = 0;
        $.getJSON("{:url('Base/liandong_c')}", function (data_a) {
            $.each(data_a.datalist, function (i, item) {
                if (i == 0) {
                    num = item.id
                }
                $('#region_id').append("<option value=" + item.id + ">" + item.region + "</option>");
            });
            $.getJSON("{:url('Base/liandong_d')}?region_id=" + num, function (data_b) {
                $.each(data_b.datalist, function (j, res) {
                    $('#branch_id').append("<option value=" + res.id + ">" + res.branch + "</option>")
                });
                form.render('select');
            })
        });
        form.on('select(region_id)', function (data_aa) {
            var region_ids = data_aa.value;
            $('#branch_id').html('');
            $.getJSON("{:url('Base/liandong_d')}?region_id=" + region_ids, function (data_bb) {
                $.each(data_bb.datalist, function (i, item) {
                    $('#branch_id').append('<option  value=' + item.id + '>' + item.branch + "</option>");
                });
                form.render('select');
            })
        });
    });
    /*function del(id) {
     if (confirm("您确定要删除吗?")) {
     $.ajax({
     type: "post",
     url: "{:url('Stafflist/staffdel')}",
     data: {"id": id},
     dataType: "json",
     success: function (a) {
     if (a) {
     alert("删除成功");
     window.location.replace("{:url('Stafflist/index')}")
     } else {
     alert("删除失败")
     }
     }
     })
     }
     }*/
</script>
</html>